﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Persistence;
using Persistence.Dao;
using System.Text.RegularExpressions;
namespace web.manage
{
    public partial class member_operate : adminBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
        {
            if (txtPassword1.Value.Trim() == txtPassword2.Value.Trim())
            {
                Domain.User u = new Domain.User();
                u.addressCorp = txtAddress.Value.Trim();
                u.email = txtEmail.Value.Trim();
                u.mobile = txtMobile.Value.Trim();
                u.password = txtPassword1.Value.Trim();
                u.postCode = Common.Utils.StrToInt(txtPostCode.Value.Trim(), 0);
                u.regDate = DateTime.Now;
                u.telephone = txtTel.Value.Trim();
                u.trueName = txtTrueName.Value.Trim();
                u.userName = txtUserName.Value.Trim();
                if (Regex.IsMatch(txtUserCode.Value.Trim(), "^[a-zA-Z]{2}$", RegexOptions.IgnoreCase))
                {
                    u.userCode = txtUserCode.Value.Trim().ToUpper();
                }
                else
                {
                    Common.Message.alert("经销商编码必须是两位英文字符");
                    return;
                }
                if (u.userName.Length == 0)
                {
                    Common.Message.alert("请输入用户名");
                    return;
                }
                if (u.telephone.Length == 0 && u.mobile.Length == 0)
                {
                    Common.Message.alert("联系电话和手机请至少输入一个");
                    return;
                }
                if (Singleton<UserDao>.Instance.SelectUserExists(u.userName) > 0)
                {
                    Common.Message.alert("用户已存在");
                    return;
                }
                Singleton<UserDao>.Instance.Insert(u);

                Common.Message.AlertFresh("注册用户成功");
            }
            else
            {
                Common.Message.alert("两次密码不一致，请重新输入");
            }
        }
    }
}
